package com.qianheng.kit.base.java.reactor.v1.handler;


import java.io.IOException;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

/**
 * 新连接处理器
 */
public class AcceptorHandler implements Runnable {
    Selector selector;
    ServerSocketChannel serverSocketChannel;

    public AcceptorHandler(Selector selector, ServerSocketChannel serverSocketChannel) {
        this.selector = selector;
        this.serverSocketChannel = serverSocketChannel;
    }

    public void run() {
        try {
            SocketChannel channel = serverSocketChannel.accept();
            if (channel != null) {
                new EchoHandler(selector, channel);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
